package barcomparator;

import java.io.File;
import java.io.FileWriter;
import java.io.FilenameFilter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.io.FileUtils;

import com.saurabh.utils.UnzipperClass;
import com.saurabh.utils.diff_match_patch;

public class UnZip {
	public static void main(String[] args) throws IOException {
		UnzipperClass unzipper = new UnzipperClass();
		String BarFile_1 = "C:\\DEV\\WKS\\IIB_POC\\barcomparator\\CODE\\BARfiles\\APP_NAME_V1.0.0.0.001F.bar";
		String BarFile_2 = "C:\\DEV\\WKS\\IIB_POC\\barcomparator\\CODE\\BARfiles\\APP_NAME_V1.0.0.0.002F.bar";

		List<String> appzipExtractedDirs_1 = new ArrayList<String>();
		List<String> appzipExtractedDirs_2 = new ArrayList<String>();

		unzipper.UnzipThis(BarFile_1, BarFile_1 + "Extracted");
		unzipper.UnzipThis(BarFile_1, BarFile_2 + "Extracted");

		File[] internal_APPZIPs_1 = new File(BarFile_1 + "Extracted").listFiles(new FilenameFilter() {

			@Override
			public boolean accept(File dir, String filename) {
				return filename.endsWith(".appzip");
			}
		});

		File[] internal_APPZIPs_2 = new File(BarFile_2 + "Extracted").listFiles(new FilenameFilter() {

			@Override
			public boolean accept(File dir, String filename) {
				return filename.endsWith(".appzip");
			}
		});

		for (int i = 0; i < internal_APPZIPs_1.length; i++) {
			unzipper.UnzipThis(internal_APPZIPs_1[i].getAbsolutePath(),
					internal_APPZIPs_1[i].getAbsolutePath() + "Extracted");
			appzipExtractedDirs_1.add(internal_APPZIPs_1[i].getAbsolutePath() + "Extracted");
		}

		for (int i = 0; i < internal_APPZIPs_2.length; i++) {
			unzipper.UnzipThis(internal_APPZIPs_2[i].getAbsolutePath(),
					internal_APPZIPs_2[i].getAbsolutePath() + "Extracted");
			appzipExtractedDirs_2.add(internal_APPZIPs_2[i].getAbsolutePath() + "Extracted");
		}

		List<File[]> files_1 = new ArrayList<File[]>();
		for (String file : appzipExtractedDirs_1) {
			files_1.add(new File(file).listFiles(new FilenameFilter() {

				@Override
				public boolean accept(File dir, String filename) {
					return filename.endsWith(".esql");
				}
			}));
		}

		List<File[]> files_2 = new ArrayList<File[]>();
		for (String file : appzipExtractedDirs_2) {
			files_2.add(new File(file).listFiles(new FilenameFilter() {

				@Override
				public boolean accept(File dir, String filename) {
					return filename.endsWith(".esql");
				}
			}));
		}
		System.out.println("Ends here");
		diff_match_patch dmp = new diff_match_patch();
		String htmml = dmp.diff_prettyHtml(dmp.diff_main(
				FileUtils.readFileToString(new File(
						"C:\\DEV\\WKS\\IIB_POC\\barcomparator\\CODE\\BARfiles\\APP_NAME_V1.0.0.0.001F.barExtracted\\Application_name.appzipExtracted\\Message_Flow_name_Compute.esql")),
				FileUtils.readFileToString(new File(
						"C:\\DEV\\WKS\\IIB_POC\\barcomparator\\CODE\\BARfiles\\APP_NAME_V1.0.0.0.002F.barExtracted\\Application_name.appzipExtracted\\Message_Flow_name_Compute.esql")),
				true));
		
		File ff = new File("C:\\Users\\admin\\Desktop\\aa.html");
		FileWriter fw = new FileWriter(ff);
		fw.write(htmml);
		fw.close();
	}
}